using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Globalization;
using System.Resources;
using System.Windows.Forms;
using System.Threading;
using System.Reflection;


namespace commonV2.forms
{
    public partial class baseDialogForm : forms.baseForm
    {
        public myTypes.DialogEvent myFormStatus = new myTypes.DialogEvent();
        public delegate void onProcess(object sender, myTypes.DialogEvent e);
        public event onProcess myOnProcess = null;
        
        //public bool isOkButtonSelected=false;
        public baseDialogForm()
        {
            InitializeComponent();
            this.myStatusStrip.Visible = true;
        }
        public virtual void ShowForm()
        {
            this.BringToFront();
            this.ShowDialog();
        }

        public override void SetLanguage()
        {
            base.SetLanguage();
            okBtn.Text = language.GetString("ok");
            closeBtn.Text = language.GetString("close");
        }

        protected virtual bool BeforeAcceptProcess() { return true; }
        protected virtual void DoProcess(object sender, myTypes.DialogEvent e)
        {
            if (myOnProcess != null) myOnProcess(sender,e);
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            try
            {
                myFormStatus.sender = sender;
                myFormStatus.isCloseClick = false;
                myFormStatus.acceptClose = false;

                this.okBtn.Enabled = false;
                if (!BeforeAcceptProcess()) return;
                DoProcess(sender, myFormStatus);
                if (myFormStatus.acceptClose) this.Close();
            }
            catch (Exception er)
            {
                this.ErrorHandler(this,er);
            }
            finally
            {
                this.okBtn.Enabled = true;
            }
        }
        private void closeBtn_Click(object sender, EventArgs e)
        {
            try
            {
                myFormStatus.sender = sender;
                myFormStatus.isCloseClick = true;
                myFormStatus.acceptClose = true;

                if (!BeforeAcceptProcess()) return;
                DoProcess(sender, myFormStatus);
                if (myFormStatus.acceptClose) this.Close();
            }
            catch (Exception er)
            {
                this.ErrorHandler(this,er);
            }
        }
    }
}

